//
//  main.m
//  demo
//
//  Created by zhouxiaobo on 15/10/20.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"
#import "Mac.h"
#import "Student.h"
#import "NSString+extention.h"

@interface Zhouxiaobo : Person{
    @private
    int sex;
}

-(int) getSex;
-(NSString *) getSexAsStr;

-(void)setSex:(int)newSex;
@end

@implementation Zhouxiaobo
-(int)getSex{
    return sex;
}

-(NSString *) getSexAsStr{
    if(sex == 0){
        return @"男";
    }else{
        return @"女";
    }
}

-(void)setSex:(int)newSex{
    sex = newSex;
}

-(void) studyOCWith:(Mac *)macbook{
    [super studyOCWith:macbook];
    NSLog(@"学习完成");
}
@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
        
        Person *p = [[Person alloc] init];
        NSLog(@"Name: %@, age: %d, height: %f", [p getName],[p getAge],[p getHeight]);
        
        Person *p1 = [[Person alloc] initWithAge:34 andHeight:168.0];
        NSLog(@"Name: %@, age: %d, height: %f", [p1 getName],[p1 getAge],[p1 getHeight]);
        
        [p1 setName:@"刘德华"];
        NSLog(@"Name: %@, age: %d, height: %f", [p1 getName],[p1 getAge],[p1 getHeight]);
        
        Mac *macbook = [[Mac alloc]init];
        [p1 studyOCWith:macbook];
        
        [macbook setInch:35];
        [macbook setCpu:64];
        
        [p1 setMac:macbook];
        NSLog(@"%@ 有一台 CPU：%d 的电脑", [p1 getName], [[p1 getMac] getCpu]);
        
        Zhouxiaobo *zxb = [[Zhouxiaobo alloc] init];
        [zxb setName:@"周晓博"];
        [zxb setSex:0];
        [zxb studyOCWith:macbook];
        [zxb setMac:macbook];
        NSLog(@"%@ 有一台 CPU：%d 的电脑，他是%@的",  [zxb getName], [[zxb getMac] getCpu], [zxb getSexAsStr]);
    
        Person *p3 = [Person getInstance];
        [p3 setName:@"黎明"];
        [p3 setMac:macbook];
        NSLog(@"%@ 有一台 CPU：%d 的电脑", [p3 getName], [[p3 getMac] getCpu]);
        
        Student *s = [[Student alloc] init];
        s.name = @"张学友";
        s.height = 168.0;
        NSLog(@"这名学生是%@，他的身高%f",s.name,s.height);
        
        NSLog(@"%@", [NSString returnCostant]);
        
        NSString *str1 = @"hello world";
        NSString *str2 = [[NSString alloc] initWithString:str1];
        NSString *str3 = [[NSString alloc] initWithUTF8String:"hello world"];
        NSString *str4 = [[NSString alloc] initWithFormat:@"he%@o wo%cld", @"ll",'r'];
        
        NSString *str5 = [NSString stringWithString:str1];
        NSString *str6 = [NSString stringWithUTF8String:"hello world"];
        NSString *str7 = [NSString stringWithFormat:@"he%@o wo%cld", @"ll",'r'];
        
        NSLog(@"%@",str1);
        NSLog(@"%@",str2);
        NSLog(@"%@",str3);
        NSLog(@"%@",str4);
        NSLog(@"%@",str5);
        NSLog(@"%@",str6);
        NSLog(@"%@",str7);
        
    }
    return 0;
}
